package com.example.elderlycare.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.elderlycare.dao.entity.BookRecord;
import com.example.elderlycare.dao.mapper.BookRecordMapper;
import com.example.elderlycare.service.BookRecordService;
import com.example.elderlycare.service.entity.BookRecordItem;
import com.example.elderlycare.service.entity.BookRecordListResponseBody;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Service
public class BookRecordServiceImpl extends ServiceImpl<BookRecordMapper, BookRecord>
        implements BookRecordService {

    @Resource
    BookRecordMapper bookRecordMapper;

    @Override
    public BookRecordListResponseBody queryBookRecords(Map<String, Object> params) {
        int total = bookRecordMapper.getBookRecordCount(params);
        List<BookRecord> bookRecords = bookRecordMapper.queryBookRecords(params);
        List<BookRecordItem> bookRecordItemList = new ArrayList<>();
        for (BookRecord bookRecord : bookRecords) {
            BookRecordItem item = BookRecordItem.builder()
                    .id(bookRecord.getId())
                    .bookerName(bookRecord.getBookerName())
                    .bookerPhone(bookRecord.getBookerPhone())
                    .nurseId(bookRecord.getNurseId())
                    .nursingHome(bookRecord.getNursingHome())
                    .bookingDate(bookRecord.getBookingDate())
                    .checkInDate(bookRecord.getCheckInDate())
                    .elderName(bookRecord.getElderName())
                    .elderNumber(bookRecord.getElderNumber())
                    .elderCertificateId(bookRecord.getElderCertificateId())
                    .elderCertificate(bookRecord.getElderCertificate())
                    .selfCareSituation(bookRecord.getSelfCareSituation())
                    .status(bookRecord.getStatus())
                    .build();
            bookRecordItemList.add(item);
        }
        return BookRecordListResponseBody.builder()
                .total(total)
                .bookRecordItemList(bookRecordItemList)
                .build();
    }
}
